import {
  Table,
  Model,
  Column,
  DataType,
  ForeignKey,
  BelongsTo,
  PrimaryKey,
  AutoIncrement,
  Unique,
  AllowNull,
  Comment
} from 'sequelize-typescript';
import { User } from './user.entity';
import { House } from './house.entity';

@Table({
  comment: '访客表',
  tableName: 'visitor',
})
export class Visitor extends Model {
  @PrimaryKey
  @AutoIncrement
  @Unique
  @AllowNull(false)
  @Comment('访客id')
  @Column(DataType.BIGINT)
  id: number;

  @AllowNull(false)
  @Comment('访客姓名')
  @Column(DataType.STRING(100))
  name: string;

  @AllowNull(false)
  @Comment('访客手机号')
  @Column(DataType.BIGINT('11'))
  phone: number;

  @AllowNull(false)
  @Comment('来访时间')
  @Column({
    type: DataType.DATE,
    defaultValue: DataType.NOW,
  })
  visitDate: number;

  @AllowNull(false)
  @Comment('访客性别0女1男')
  @Column(DataType.ENUM('0', '1'))
  gender: number;

  @Comment('通行证url')
  @Column(DataType.STRING)
  url: string;

  @AllowNull(false)
  @Comment('状态：1生效中0已失效')
  @Column({
    type: DataType.ENUM('0', '1'),
    defaultValue: '0'
  })
  status: string;

  @ForeignKey(() => User)
  @Column(DataType.BIGINT)
  userId: number;

  @BelongsTo(() => User) // 指定这是一个属于（BelongsTo）关系
  user: User;

  @ForeignKey(() => House)
  @Column(DataType.BIGINT)
  houseId: number;

  @BelongsTo(() => House) // 指定这是一个属于（BelongsTo）关系
  house: House;
}
